<template>
  <div>
    <!-- 面包屑区域 组件化传值 -->
    <Header :titleName="titleObj"></Header>
    <!-- 卡片试图 -->
    <el-card>
      <!-- 搜索框 和 确认框 -->
      <el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-input
              placeholder="请输入内容"
              v-model="queryInfo.query"
              clearable
              @clear="getOrdersList"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="getOrdersList"
              ></el-button>
            </el-input>
          </el-col>
        </el-row>
      </el-row>
      <!-- table 列表 -->
      <el-table :data="ordersList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款">
          <!-- 0 未支付 1 支付宝 2 微信 3 银行卡  -->
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status == '0'"
              >未支付</el-tag
            >
            <el-tag type="success" v-if="scope.row.pay_status == '1'"
              >支付宝</el-tag
            >
            <el-tag type="success" v-if="scope.row.pay_status == '2'"
              >微信</el-tag
            >
            <el-tag type="success" v-if="scope.row.pay_status == '3'"
              >银行卡</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- {{scope.row}} -->
            <el-button type="primary" size="small" @click="showBtn(scope.row)"
              >修改地址</el-button
            >
            <el-button type="success" size="small" @click="showPressgres"
              >查看物流</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>

    <!-- 修改对话框区域 -->
    <el-dialog
      title="编辑用户"
      :visible.sync="addDialogVisible"
      width="40%"
      @close="editDialogClose"
    >
      <el-form
        :model="addOrderForm"
        :rules="addOrderRules"
        ref="addOrderRef"
        label-width="70px"
      >
        <el-form-item label="城市区/县" prop="address1" label-width="95px">
          <el-cascader
            v-model="addOrderForm.address1"
            :options="cityDataList"
            :props="optionsCate"
            @change="handleChange"
            clearable
            change-on-select
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2" label-width="95px">
          <el-input v-model="addOrderForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addOrderOk">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流显示对话框区域 -->
    <el-dialog
      title="编辑用户"
      :visible.sync="pressgreValidate"
      width="40%"
      @close="pressgreDialogClose"
    >
      <el-form label-width="70px">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.time"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import Header from '../shard/header.vue'
import cityDataList from './citydata.js'
export default {
  data() {
    return {
      titleObj: { firstName: '订单管理', scendName: '订单列表' },
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      addOrderForm: {
        address1: [],
        address2: '',
      },
      addOrderRules: {
        address1: [{ required: true, message: '请选择地区', trigger: 'blur' }],
        address2: [
          { required: true, message: '请输入具体地址', trigger: 'blur' },
        ],
      },
      total: 0,
      ordersList: [],
      addDialogVisible: false,
      cityDataList,
      selectedKeys: [],
      optionsCate: {
        expandTrigger: 'hover',
      },
      pressgreValidate: false,
      activities:[]
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList() {
      const { data: res } = await this.$http.get('/orders', {
        params: this.queryInfo,
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败！')
      }
      this.$message.success('获取订单列表成功')
      this.ordersList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange(pageSize) {
      this.queryInfo.pagesize = pageSize
      this.getOrdersList()
    },
    handleCurrentChange(pagenum) {
      this.queryInfo.pagenum = pagenum
      this.getOrdersList()
    },
    showBtn(row) {
      console.log(row)
      this.addDialogVisible = true
    },
    editDialogClose() {
      this.$refs.addOrderRef.resetFields()
    },
    pressgreDialogClose() {},
    addOrderOk() {},
    handleChange() {},
    async showPressgres() {
      // this.pressgreValidate = true;
      // const  { data: res } = await this.$http.get('/kuaidi/1106975712662')
      // if (res.meta.status !== 200) {
      //   return this.$message.error('获取物流列表失败！')
      // }
      // this.$message.success('获取物流列表成功')
      // this.activities = res.data
    },
  },
  components: {
    Header,
  },
}
</script>

<style>
.el-input {
  width: 100%;
}
.el-cascader {
  width: 100%;
}
</style>